<template>
	<view class="page">
		<Navbar :title="title"></Navbar>
		<view v-html="detailData" class="u-font-32"></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			id: 1,
			title: '详情',
			detailData: ''
		};
	},
	onLoad(e) {
		this.id = e.id;
		this.$u.api.NewsDetails({ id: this.id }).then(res => {
			this.detailData = this.imageSrcToBaseUrl(res.data.Body);
		});
	},
	methods: {
		imageSrcToBaseUrl(beforeHtml) {
			let that = this;
			let afterHtml = '';
			if (beforeHtml.indexOf('<img') != -1) {
				afterHtml = beforeHtml.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function(img, src) {
					return '<img style="width: 100%;" src="' + that.imgBaseUrl + src + '"/>';
				});
				return afterHtml;
			} else {
				return beforeHtml;
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.page {
	padding: 20rpx;
	background-color: #fff;
}
</style>
